package com.boc.langxiang.ui.activity.me;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import com.boc.langxiang.App;
import com.boc.langxiang.R;
import com.boc.langxiang.contract.common.AccountUpdatePasswordContract;
import com.boc.langxiang.presenter.common.AccountUpdatePasswordPresenter;
import com.boc.langxiang.ui.activity.common.RegistAndLoginActivity;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 修改密码
 */
public class SetModifyPasswordActivity extends MeBaseToolBarActivity implements AccountUpdatePasswordContract.View {

    @BindView(R.id.et_me_set_lastpwd)
    EditText etMeSetLastpwd;
    @BindView(R.id.et_me_set_newpwd)
    EditText etMeSetNewpwd;
    @BindView(R.id.et_me_set_againpwd)
    EditText etMeSetAgainpwd;
    private AccountUpdatePasswordPresenter mPresenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_set_modify_password);
        ButterKnife.bind(this);
        setToolBarTitle("修改密码");
        mPresenter = new AccountUpdatePasswordPresenter(this);

    }

    @Override
    protected int setToolBarBackgroundColor() {
        return Color.WHITE;
    }

    @Override
    protected int setToolBarBackImg() {
        return R.drawable.icon_me_left;
    }

    @Override
    protected int setToolBarTitleColor() {
        return Color.BLACK;
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void onError(String code, String msg) {
        Toast.makeText(App.getInstance(), msg, Toast.LENGTH_SHORT).show();
        etMeSetLastpwd.setText("");
    }

    @OnClick(R.id.btn_me_set_commitpwd)
    public void onClick(View v) {
        String lastPwd = etMeSetLastpwd.getText().toString();
        String newPwd = etMeSetNewpwd.getText().toString();
        String againPwd = etMeSetAgainpwd.getText().toString();
        if (TextUtils.isEmpty(lastPwd) || TextUtils.isEmpty(newPwd) || TextUtils.isEmpty(againPwd)) {
            Toast.makeText(App.getInstance(), "输入不能为空", Toast.LENGTH_SHORT).show();
            return;
        }

        if (!newPwd.equals(againPwd)) {
            Toast.makeText(App.getInstance(), "两次输入的密码不相同", Toast.LENGTH_SHORT).show();
            etMeSetNewpwd.setText("");
            etMeSetAgainpwd.setText("");
            return;
        }

        mPresenter.accountUpdatePassword(lastPwd, newPwd, againPwd);
    }

    @Override
    public void startToLoginActivity() {
        startActivity(new Intent(mContext, RegistAndLoginActivity.class));
        finish();
    }
}
